home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
MainForm.cs
< prev
next >
Wrap
Text File
|
2005-06-05
|
6KB
|
243 lines
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using PCIBird;
using MyCustomControls;
//using Bluebit.MatrixLibrary; //maybe buy this full package later
namespace SampleGUI
{
//list some definitions
/// <summary>
/// Summary description for MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
//Control Components
private System.ComponentModel.Container components = null;
public ViewPanel viewPanel;
private Label lbl_Position;
private Label lbl_;
private Button btn_TrackingSystem;
private Button btn_OpenFile;
public CTControlPanel ctControlPanel;
//public CustomControl1 cc1;
public ScrollSlider uc1;
//tracking system objects
private TrackingSystem trackingSystem;
private bool trackingSystemOnOff = false;
private bool trackingSystemInitialized = false;
public RichTextBox rtb = new RichTextBox();
public System.Windows.Forms.Form trackingForm;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//add the main view panel
viewPanel = new ViewPanel();
viewPanel.BorderStyle = BorderStyle.Fixed3D;
Controls.Add( viewPanel );
// add the initialize tracking system button
btn_TrackingSystem = new Button();
btn_TrackingSystem.Text = "Initialize Tracking System";
btn_TrackingSystem.Size = new Size(150,30);
btn_TrackingSystem.Click += new EventHandler(HandleTrackingSystem);
Controls.Add( btn_TrackingSystem );
lbl_Position = new Label();
lbl_Position.Location = new Point(10,100);
lbl_Position.Size = new Size(120,100);
Controls.Add( lbl_Position );
btn_OpenFile = new Button();
btn_OpenFile.Location = new Point(0,50);
btn_OpenFile.Text = "Open File";
Controls.Add( btn_OpenFile );
btn_OpenFile.Click += new EventHandler(OpenFile_OnClick);
lbl_ = new Label();
Controls.Add( lbl_ );
lbl_.Location = new Point(0,500);
lbl_.Size = new Size(200,200);
lbl_.Text = "Dummy Label";
viewPanel.mainSliceView.lbl = lbl_;
ctControlPanel = new CTControlPanel();
ctControlPanel.Location = new Point(0,200);
ctControlPanel.Size = new Size(300,150);
Controls.Add(ctControlPanel);
ctControlPanel.Show();
uc1 = new ScrollSlider();
uc1.Location = new Point(0,350);
//Controls.Add(uc1);
//set the window up to start by calling resize callback
MainForm_Resize(new object(), new EventArgs());
//set double buffering to ON
this.SetStyle(ControlStyles.DoubleBuffer,true);
//Set up the tracking system
trackingSystem = new TrackingSystem();
this.Resize += new EventHandler(MainForm_Resize);
}
void MainForm_Resize(object sender, EventArgs e)
{
int cx, cy;
Rectangle rect = new Rectangle();
cx = this.ClientSize.Width;
cy = this.ClientSize.Height;
rect.Width = cy > (int)(4/3.0*cx)? cx : (int)(3/4.0*cy);
rect.Height = (int)(4/3.0*rect.Width);
rect.X = cx - rect.Width;
rect.Y = 0;
this.viewPanel.SetBounds(rect.X,rect.Y,rect.Width,
rect.Height);
}
void HandleTrackingSystem(object sender, EventArgs e)
{
if(!trackingSystemInitialized)
{
trackingSystem.Initialize();
trackingSystemInitialized = true; //only initialized once
btn_TrackingSystem.Text = "Start Tracking System";
TrackingSystemForm tsf = new TrackingSystemForm(trackingSystem);
tsf.Show();
return;
}
if(trackingSystemOnOff)
{
trackingSystemOnOff = false;
btn_TrackingSystem.Text = "Start Tracking System";
return;
}
else
{
trackingSystemOnOff = true;
btn_TrackingSystem.Text = "Stop Tracking System";
while(trackingSystemOnOff)
{
PositionAnglesReading par = trackingSystem.sensor[0].GetAsyncReading();
string str = "x:" + par.x + "\ny:" + par.y + "\nz:" + par.z + "\n";
lbl_Position.Text = str;
//viewPanel.SetPosition((float)par.x,(float)par.y,(float)par.z);
viewPanel.Refresh();
}
}
}
void OpenFile_OnClick(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = ".mhd";
dlg.Filter = "Meta Files (*.mhd)|*.mhd|" +
"DVD Files (*.dvd)|*.dvd|" +
"Raw Files (*.raw)|*.raw";
dlg.InitialDirectory = "C:\\Documents and Settings\\Tim Soper\\My Documents\\"
+ "CatheterScope Project\\CT Scans\\";
if(dlg.ShowDialog() == DialogResult.OK)
{
//close the file open browser
dlg.Dispose();
Application.DoEvents();
Scan scan = new Scan();
scan.FilePath = dlg.FileName;
int error = scan.Read();
if(error.Equals(0))
{
viewPanel.mainSliceView.lbl = lbl_;
viewPanel.LoadScan(scan);
ctControlPanel.LinkToScan(scan);
ctControlPanel.LinkToViewPanel(viewPanel);
viewPanel.Refresh();
}
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 566);
this.Name = "MainForm";
this.Text = "Main Form";
this.Load += new System.EventHandler(this.MainForm_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}
private void MainForm_Load(object sender, System.EventArgs e)
{
}
}
}